import { defineStore } from 'pinia'
import { Http } from '../api/api';
import { userInfoFace } from '../utils/types';

export const useStore = defineStore('main', {
    state: () => ({
        count: 2000,
        userInfo: null,
        roleList: [],
        isCollapse: false,
        urlList: [],
        annoList: [],
        userList: [],
        xuekeList: [],

        adviseList: [],

        myRouterList: [],

        fromRouteName: '',
    }),
    getters: {

    },
    actions: {
        changefromRouteName(payload?: any) {
            this.fromRouteName = payload;
        },
        changeCount(payload: number) {
            this.count += payload;
        },
        setUserInfo(payload?: userInfoFace | any) {
            this.userInfo = payload;
        },
        async getRoleListAsync(payload?: any) {
            let res = await Http.getrolelist(payload) as unknown as any;
            if (res.code == 200) {
                this.roleList = res.result;
            }
        },

        async getAnnoListAsync(payload?: any) {
            let res = await Http.getannolist(payload) as unknown as any;
            if (res.code == 200) {
                this.annoList = res.result;

            }
        },
        getAnnoList(payload?: any) {
            this.annoList = payload
        },

        async getXuekeListAsync(payload?: any) {
            let res = await Http.getxuekelist(payload) as unknown as any;
            if (res.code == 200) {
                this.xuekeList = res.result;
            }
        },

        async getUserListAsync(payload?: any, callback?: any) {
            let res = await Http.getuserlist(payload) as unknown as any;
            if (res.code == 200) {
                this.userList = res.result;
                callback(res.total)
            }
        },
        getUserList(payload?: any) {
            this.userList = payload
        },

        async getAdivseListAsync(payload?: any, callback?: any) {
            let res = await Http.getadviselist(payload) as unknown as any;
            if (res.code == 200) {
                this.adviseList = res.result;

            }
        },
        getAdviseList(payload?: any) {
            this.adviseList = payload
        },

        changeRoleList(payload?: any) {
            this.roleList = payload;
        },
        changeCollapse(payload: boolean) {
            this.isCollapse = payload;
        },
        changeurlList(payload: any) {
            this.urlList.push(payload)
        },

        getMyRouterList(payload?: any) {
            this.myRouterList = payload;
        }
    }
})